package com.fcb.pois.util; /**
 * @author lujianqing
 * @description:
 * @ClassName POIEcxelCreHigh
 * @since 2021-10-21 11:01
 */
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;

public class PoiUtil {
    public static void doWriteSubId(List<List<String>> mapList, String rootPath,String subIdName) throws IOException {
        //创建Excel文件薄
        XSSFWorkbook workbook=new XSSFWorkbook();
        //创建工作表sheeet
        Sheet sheet=workbook.createSheet();
        int size = mapList.size();
        //追加数据
        for (int i=0;i<size;i++){
            Row nextrow=sheet.createRow(i);
            List<String> ss =  mapList.get(i);
            for(int j = 0 ;j < ss.size();j++){
                String value = ss.get(j);
                Cell cell2=nextrow.createCell(j);
                cell2.setCellValue(value);
            }

        }
        //创建一个文件
        File file=new File(rootPath+"/"+subIdName);
        file.createNewFile();
        FileOutputStream stream= new FileOutputStream(file);
        workbook.write(stream);
        stream.close();
    }
    
    public static void doWriteMerge(List<List<String>> mapList, String rootPath, String targetName) throws IOException {
        //创建Excel文件薄
        XSSFWorkbook workbook=new XSSFWorkbook();
        //创建工作表sheeet
        Sheet sheet=workbook.createSheet();
        int size = mapList.size();
        //追加数据
        for (int i=0;i<size;i++){
            Row nextrow=sheet.createRow(i);
            List<String> ss =  mapList.get(i);
            for(int j = 0 ;j < ss.size();j++){
                String value = ss.get(j);
                Cell cell2=nextrow.createCell(j);
                cell2.setCellValue(value);
            }

        }
        //创建一个文件
        File file=new File(rootPath+"/"+targetName);
        file.createNewFile();
        FileOutputStream stream= new FileOutputStream(file);
        workbook.write(stream);
        stream.close();
    }

    public static void doWriteMergeLast(List<List<String>> mapList, String rootPath, String targetName) throws IOException {
        //创建Excel文件薄
        XSSFWorkbook workbook=new XSSFWorkbook();
        //创建工作表sheeet
        Sheet sheet=workbook.createSheet();
        int size = mapList.size();
        //追加数据
        for (int i=0;i<size;i++){
            Row nextrow=sheet.createRow(i);
            List<String> ss =  mapList.get(i);
            for(int j = 0 ;j < ss.size();j++){
                String value = ss.get(j);
                Cell cell2=nextrow.createCell(j);
                cell2.setCellValue(value);
            }

        }
        //创建一个文件
        File file=new File(rootPath+"/"+targetName);
        file.createNewFile();
        FileOutputStream stream= new FileOutputStream(file);
        workbook.write(stream);
        stream.close();
    }
}

